<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ArrayUtilitiesTest</title>

<link rel="stylesheet"
	href="http://code.jquery.com/qunit/qunit-1.15.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>
<script src="../../../main/js/util/Logger.js"></script>
<script src="../../../main/js/util/ArrayUtilities.js"></script>

<script>
    var LOGGER = new Logger();

    QUnit.test("ArrayUtilities.addAll()", function(assert)
    {
        // Setup.
        var array1 = [ 1 ];
        var array2 = [ 2, 3, 4 ];

        // Run.
        ArrayUtilities.addAll(array1, array2);

        // Verify.
        assert.equal(array1.length, 4);
        assert.equal(array1[0], 1);
        assert.equal(array1[1], 2);
        assert.equal(array1[2], 3);
        assert.equal(array1[3], 4);
    });

    QUnit.test("ArrayUtilities.contains()", function(assert)
    {
        var array = [ 1, 2, 3, 4 ];
        assert.ok(!ArrayUtilities.contains(array, 0));
        assert.ok(ArrayUtilities.contains(array, 1));
        assert.ok(ArrayUtilities.contains(array, 2));
        assert.ok(ArrayUtilities.contains(array, 3));
        assert.ok(ArrayUtilities.contains(array, 4));
        assert.ok(!ArrayUtilities.contains(array, 5));
    });

    QUnit.test("ArrayUtilities.randomElement()", function(assert)
    {
        var array = [ 1, 2, 3, 4 ];

        for (var i = 0; i < 10; i++)
        {
            assert.ok(ArrayUtilities.contains(array, ArrayUtilities
                    .randomElement(array)));
        }
    });

    QUnit.test("ArrayUtilities.remove()", function(assert)
    {
        // Setup.
        var array = [ 1, 2, 3, 4 ];

        // Run.
        ArrayUtilities.remove(array, 2);

        // Verify.
        assert.equal(array.length, 3);
        assert.equal(array[0], 1);
        assert.equal(array[1], 3);
        assert.equal(array[2], 4);
    });

    QUnit.test("ArrayUtilities.shuffle()", function(assert)
    {
        var array = [ 1, 2, 3, 4 ];

        for (var i = 0; i < 10; i++)
        {
            ArrayUtilities.shuffle(array);
            // LOGGER.trace("array = " + array);
            assert.equal(array.length, 4);
            assert.ok(0 < array[0] && array[0] < 5);
        }
    });
</script>
</head>
<body>
	<div id="qunit"></div>
</body>
</html>
